package com.deke.baby.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.deke.baby.vo.BabyFamilyVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.deke.common.annotation.Log;
import com.deke.common.core.controller.BaseController;
import com.deke.common.core.domain.AjaxResult;
import com.deke.common.enums.BusinessType;
import com.deke.baby.domain.BabyFamily;
import com.deke.baby.service.IBabyFamilyService;
import com.deke.common.utils.poi.ExcelUtil;
import com.deke.common.core.page.TableDataInfo;

/**
 * 家庭Controller
 *
 * @author deke
 * @date 2023-06-28
 */
@RestController
@RequestMapping("/baby/family")
public class BabyFamilyController extends BaseController
{
    @Autowired
    private IBabyFamilyService babyFamilyService;

    /**
     * 查询家庭列表
     */
    @PreAuthorize("@ss.hasPermi('baby:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(BabyFamily babyFamily)
    {
        startPage();
        List<BabyFamily> list = babyFamilyService.selectBabyFamilyList(babyFamily);
        return getDataTable(list);
    }

    /**
     * 导出家庭列表
     */
    @PreAuthorize("@ss.hasPermi('baby:family:export')")
    @Log(title = "家庭", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BabyFamily babyFamily)
    {
        List<BabyFamily> list = babyFamilyService.selectBabyFamilyList(babyFamily);
        ExcelUtil<BabyFamily> util = new ExcelUtil<BabyFamily>(BabyFamily.class);
        util.exportExcel(response, list, "家庭数据");
    }

    /**
     * 获取家庭详细信息
     */
    @PreAuthorize("@ss.hasPermi('baby:family:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(babyFamilyService.selectBabyFamilyById(id));
    }

    /**
     * 新增家庭
     */
    @PreAuthorize("@ss.hasPermi('baby:family:add')")
    @Log(title = "家庭", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BabyFamilyVo babyFamily)
    {
        babyFamilyService.insertBabyFamily(babyFamily);
        return AjaxResult.success();
    }

    /**
     * 修改家庭
     */
    @PreAuthorize("@ss.hasPermi('baby:family:edit')")
    @Log(title = "家庭", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BabyFamilyVo babyFamily)
    {
        babyFamilyService.updateBabyFamily(babyFamily);
        return AjaxResult.success();
    }

    /**
     * 删除家庭
     */
    @PreAuthorize("@ss.hasPermi('baby:family:remove')")
    @Log(title = "家庭", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(babyFamilyService.deleteBabyFamilyByIds(ids));
    }
}
